package com.zzy.app.config;

import com.zzy.app.config.condition.LinuxCondition;
import com.zzy.app.config.condition.WindowsCondition;
import com.zzy.app.entity.Person;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;

/**
 * 研究带条件注入bean
 * 可以看到加@Conditionnal注解前后，注入进去的bean发生了变化
 */
public class MainConfig4 {

    @Bean("zzy")
    public Person person() {
        System.out.println("此时实例化了person bean！");
        return new Person("zzy", 18);
    }

    @Conditional(WindowsCondition.class)
    @Bean("bill")
    public Person person1() {
        return new Person("bill", 68);
    }

    @Conditional(LinuxCondition.class)
    @Bean("linus")
    public Person person2() {
        return new Person("linus", 88);
    }
}
